import type { IUpdateListDto, ICreateListDto } from '@/stores/interfaces/list.interface'
import { io } from 'socket.io-client'

export const socket = io('ws://localhost:4936/todo-list', {
  transports: ['websocket'],
  auth: {
    authorization: 'Bearer ' + localStorage.getItem('token')
  }
})

socket.on('connect', () => {
  socket.emit('join')
})

export function SocketTodoCreate(payload: ICreateListDto) {
  socket.emit('todo-create', payload)
}

export function SocketTodoDelete(id: string) {
  socket.emit('todo-delete', { id })
}

export function SocketTodoUpdate(payload: IUpdateListDto) {
  socket.emit('todo-update', payload)
}
